import instance from '@/utils/axios.js'

function getChannelList() {
    return instance({
        url: '/v1_0/channels',
        method:'get'
    })
}


function getArticleList({ channel_id, timestamp }) {
    return instance({
        url: '/v1_0/articles',
        method: 'get',
        params: {
            channel_id,
            timestamp,
            with_top:1
        }
    })
}

// 请求文章详情

function getArticleInfo(id) {
    return instance({
        url: '/v1_0/articles/' + id,
        method:'get'
    })
}


// 关注用户
function addfollowUser({target}) {
    return instance({
        url: '/v1_0/user/followings',
        method: 'post',
        data:{target}
    })
}
// 取消关注
function removerFollowUser({target}) {
    return instance({
        url:'/v1_0/user/followings/' + target,
        method: 'delete',
    })
}
// 点赞
function addPraise(id) {
    return instance({
        url:'/v1_0/article/likings' ,
        method: 'post',
        data: {
            target:id
        }
    })
}
// 取消点赞
function removerPraise(id) {
    return instance({
        url:`/v1_0/article/likings/${id}`,
        method: 'delete',
    })
}
// 添加不喜欢
function dislikes(id) {
    return instance({
        url:'/v1_0/article/dislikes' ,
        method: 'post',
        data: {
            target:id
        }
    })
}
// 取消不喜欢
function remoDislikes(id) {
    return instance({
        url:`/v1_0/article/dislikes/${id}`,
        method: 'delete',
    })
}

// 搜索推荐词

function getSuggestion(q) {
    return instance({
        url: '/v1_0/suggestion',
        method: 'get',
        params:{q}
    })
}
  
// 搜索结果列表
function getSearchList({ page, q }) {
    return instance({
        url: "/v1_0/search",
        method: 'get',
        params: {
            per_page: 10,
            page,
            q
        }
    })
}
export {
    getChannelList, getArticleList,
    getArticleInfo, addfollowUser, removerFollowUser,
    addPraise, removerPraise, getSuggestion, dislikes, remoDislikes,getSearchList
}